package com.TeacherInfoServer.utils;

import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;

@Slf4j
public class ExcelFormatDateUtil {
    public static String formatDate(String date) {
        String[] dateFormats = {
                "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss", "yyyy.MM.dd HH:mm:ss",
                "yyyy-MM-dd", "yyyy/MM/dd", "yyyy.MM.dd",
                "yy-MM-dd", "yy/MM/dd", "yy.MM.dd"
        };

        for (String dateFormat : dateFormats) {
            try {
                SimpleDateFormat inputFormat = new SimpleDateFormat(dateFormat);
                inputFormat.setLenient(false);
                SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
                return outputFormat.format(inputFormat.parse(date));
            } catch (ParseException e) {
                // 忽略并尝试下一个格式
            }
        }

        log.error("Date format error for: {}", date);
        return null;
    }
}
